<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>

    <template id="temp">
        <h2>{{fullName}}</h2>
        <button @click="changeFullName">修改fullName</button>
    </template>

    <script src="../js/vue.js"></script>
    <script>
        const App = {
            template:"#temp",
            data() {
                return {
                    firstName: 'luffy',
                    lastName: 'ACE',
                }
            },
            computed: {
                // getter的语法糖
                // fullName() {
                //     return this.firstName + ' - ' + this.lastName
                // }

                fullName: {
                    // 如果是这个计算属性是对象会直接调用get
                    get: function() {
                        return this.firstName + ' - ' + this.lastName
                    },
                    set: function(val) {
                        // console.log(val)
                        let names = val.split(' ');
                        this.firstName = names[0];
                        this.lastName = names[1];
                    }
                }
            },
            methods: {
                changeFullName() {
                    //方法调用计算属性时 会触发set
                    this.fullName = "Sabo Long"
                }
            },
        }

        Vue.createApp(App).mount("#app")
    </script>
</body>
</html>